package com.ytc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytc.model.Histroy;
import com.ytc.model.Prize;
import com.ytc.service.HistroyService;
import com.ytc.service.PrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
@RequestMapping("/prize")
public class PrizeController {
    @Autowired
    private PrizeService prizeService;
    @Autowired
    private HistroyService histroyService;

    @RequestMapping("queryprizeList")
    public String queryprizeList(Model model, @RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum, Prize prize){
        //分页计算分页的提条数以及开始的页数
        PageHelper.startPage(pageNum,3);
        List<Prize> list=prizeService.queryprizeList(prize);
        PageInfo<Prize> pageInfo=new PageInfo<Prize>(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("prize",prize);
        model.addAttribute("list",list);
        return "prize/showPrize";
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        prizeService.queryprizeList();
        return "prize/addPrize";
    }
    @RequestMapping("queryHistroyList")
    public String queryHistroyList(Model model,@RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum){
    PageHelper.startPage(pageNum,3);
        list = histroyService.queryHistroyList(pageNum);
        PageInfo<Histroy> pageInfo=new PageInfo<>(list);
        model.addAttribute("pageInfo",pageInfo);
        return "histroy/showHistroy";
    }

}
